Skip to content

Conversation

@FloorIsGround
Copy link

Removed the stateless http additions by @ranjitodedra as they weren't necessary for the issue and may add confusion as stateless_http isn't necessary for a streamable http mcp service.

Motivation and Context

Fixing #1494 and also added an example with more detailed explanation of attaching ASGI services through lifespan.

How Has This Been Tested?

I tested the new example with information from #1484. The main issue was attempting to run two separate ASGI services at the same time rather than mounting them to a main one to call other ASGI services.

Breaking Changes

No there are no breaking changes just documentation and examples.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

As was said in Issue #1494 they found they could mount existing server routes onto an mcp server but were struggling on the configuration to run multiple services asynchronously. It is possible to do so with Starlette examples, the mcp service, as well as other asynchronous services can be started and stopped by a context manager lifespan function, on a Starlette app call.

The confusion with stateless_http is probably that a streamable_http mcp server requires stateless_http due to its name, unless you look deeper you won't find that it is only tied to if requests track sessions or carry persistence between requests. I removed the added stateless_http since it wasn't necessary for the examples in question.

ranjitodedra and others added 8 commits October 18, 2025 01:01
Fixes modelcontextprotocol#1484
- Add contextlib import and lifespan function to all mounting examples
- Add stateless_http=True parameter to FastMCP constructors
- Add lifespan=lifespan parameter to Starlette apps
- Update README.md documentation with correct examples
- Fixes RuntimeError: Task group is not initialized. Make sure to use run()

Resolves the issue where mounting StreamableHTTP servers to existing ASGI
applications would fail with RuntimeError due to missing session manager
initialization.
Run scripts/update_readme_snippets.py to sync documentation with code changes.
…lifespan

Extend Fix/streamable http mounting lifespan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants